//
//  CESecretVC.m
//  digitalCurrency
//
//  Created by 默认账户 on 2019/4/3.
//  Copyright © 2019 XinHuoKeJi. All rights reserved.
//

#import "CESecretVC.h"
#import "CELoginSetVC.h"
#import "CECaptialSettingVC.h"
#import "CECaptialResettingVC.h"
//#import "ShowLoGinVC.h"
#import "AccountSettingInfoModel.h"
#import "MineNetManager.h"

@interface CESecretVC ()

@property (nonatomic, copy) NSArray *titles;
@property (nonatomic,strong) AccountSettingInfoModel *accountInfo;

@end

@implementation CESecretVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.viewTitle.text = LocalizationKey(@"Account setting");
    [self.view addSubview:self.tableView];
    self.tableView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 220);
    _titles = @[LocalizationKey(@"Change login password"),LocalizationKey(@"Change asset password")];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"setcell"];
    self.tableView.rowHeight = 50;
    self.tableView.separatorColor = [UIColor clearColor];

}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self accountSettingData];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _titles.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"setcell"];
    cell.accessoryType    = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle   = UITableViewCellSelectionStyleNone;
    
    UIView *lineView = [[UIView alloc]init];
    [cell.contentView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(17);
        make.right.equalTo(-17);
        make.bottom.equalTo(0);
        make.height.equalTo(0.5);
    }];
    lineView.backgroundColor = tTableViewCellLine;
    
    cell.textLabel.text = _titles[indexPath.row];
    cell.textLabel.textColor = tThreeColor;
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row) {
        BOOL fundsV = [self.accountInfo.fundsVerified boolValue];
        if (fundsV) {
            CECaptialResettingVC *vc = [[CECaptialResettingVC alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
        else {
            CECaptialSettingVC *vc = [[CECaptialSettingVC alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
        
    }
    else {
        CELoginSetVC *vc = [[CELoginSetVC alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

//MARK:--账号设置的状态信息获取
-(void)accountSettingData {
    
    [MineNetManager accountSettingInfoForCompleteHandle:^(id resPonseObj, int code) {
        NSInteger rescode = [resPonseObj[@"code"] integerValue];
        if (code) {
            if (rescode == 0) {
                if ([[NSString stringWithFormat:@"%@",resPonseObj[@"data"][@"result"]] isEqualToString:@"0"]) {
                    self.accountInfo = [AccountSettingInfoModel mj_objectWithKeyValues:@{@"fundsVerified":@"0"}];
                }
                else{
                    self.accountInfo = [AccountSettingInfoModel mj_objectWithKeyValues:@{@"fundsVerified":@"1"}];
                }
                                
                [self getAccountSettingStatus];
            }
            else if (rescode == -1000001){
                [ShowLoGinVC showLoginVc:self withTipMessage:resPonseObj[MESSAGE]];
            }
            else {
                [self.view makeToast:resPonseObj[MESSAGE] duration:1.5 position:CSToastPositionCenter];
            }
        }
        else {
            [self.view makeToast:LocalizationKey(@"noNetworkStatus") duration:1.5 position:CSToastPositionCenter];
        }
    }];
}

//MARK:--整理账号设置的信息状态
-(void)getAccountSettingStatus {
    if ([self.accountInfo.fundsVerified integerValue] == 0) {
        _titles = @[LocalizationKey(@"Change login password"),LocalizationKey(@"Set asset password")];
        [self.tableView reloadData];
    }
}


@end
